package com.googlecode.jsitemap;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @author Denis Migol
 * 
 */
public final class Util {
	/**
	 * Don't let anyone instantiate this class.
	 */
	private Util() {
	}

	public static final String UTF8 = "UTF-8";

	public static String encode(final String url) {
		try {
			return URLEncoder.encode(url, UTF8);
		} catch (final UnsupportedEncodingException e) {
			return null;
		}
	}

	public static String escape(final String s) {
		String ret = s;
		ret = ret.replace("&", "&amp;");
		ret = ret.replace("'", "&apos;");
		ret = ret.replace("\"", "&quot;");
		ret = ret.replace(">", "&gt;");
		ret = ret.replace("<", "&lt;");
		return ret;
	}
}
